home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-01 | 1.3 KB | 48 lines | [TEXT/DWat] |
- % A demonstration of non-linear curve
- % fitting in Asymptote.
-
- % Fit a double Gaussian to a spectrum.
- % Ask the user if they would like to use
- % preset initial guesses for the parameters
- % of the Gaussians or if they would like
- % to enter the parameters using the graph
- % cursor.
-
- % Set up and read the data file
- fullscreen yes
- datafile Gaussian Data
- datalines 2
- readcol x 1
- readcol y 2
- close \f
- rpn 4 >e % Put a constant error of 4 in the e vector
- graphlimits
- pointsymbol 4 cross
- plotpoints
- drawframe
- drawxlabel Frequency
- drawylabel Intensity
-
- % Ask whether they want to use the mouse
- % to enter guesses for the Gaussian parameters
- set GetParameters no
- ask GetParameters Yes No I need guesses for the fit parameters. $
- Would you like to enter them with the graph cursor?
-
- % Run the appropriate script
- if GetParameters then GetParameters else SetParameters
-
- % Now do the fit
- set plot_each_fit yes
- fitxy 6 x a0 - a1 / 2 y^x -1 * e^x a2 * x a3 - a4 / 2 y^x -1 * e^x a5 * +
-
- % To plot the fit, use four times as many points:
- npts npts 4 *
- % Which fill the entire graph range:
- xrange xleft xright
- close xrange % Close the xrange script
-
- % Calculate the fit at each x
- rpn <x a0 - a1 / 2 y^x -1 * e^x a2 * <x a3 - a4 / 2 y^x -1 * e^x a5 * + >y
- % Plot the fit on the graph
- plotline